<?php
/**
 * Created by JetBrains PhpStorm.
 * User: ZhangYi
 * Date: 11-9-3
 * Time: 下午7:54
 * To change this template use File | Settings | File Templates.
 */

class questionComponents extends sfComponents
{
    public function executeEntry(sfWebRequest $request)
    {
        $this->question_channel = Doctrine_Core::getTable('QuestionChannel')->createQuery('q')
                ->addWhere('q.is_on_top=?', 1)->addWhere('q.is_available=?', 1)->addOrderBy('q.create_time desc')
                ->fetchOne();

        if ($this->question_channel != null)
            $this->questions = Doctrine_Core::getTable('question')->createQuery('q')
                    ->addWhere("q.question_channel_id = ?", $this->question_channel->getId())
                    ->addWhere("q.is_available=?", 1)
                    ->addOrderBy('q.is_on_top desc')
                    ->addOrderBy("q.create_time desc")->limit(20)->execute();
    }

    public function executeQuestionList(sfWebRequest $request)
    {
        $id = $request->getParameter("id");
        if ($id == null) $id = $this->qcId;
        $this->questions = Doctrine_Core::getTable('question')->createQuery('q')
                ->addWhere('q.question_channel_id=?', $id)->addWhere("q.is_available=?", 1)
                ->addOrderBy('q.is_on_top desc')
                ->addOrderBy('q.create_time desc')->limit(20)
                ->execute();
        $this->channel_id = $id;
    }

    public function executeQuestionChannel(sfWebRequest $request)
    {
        $id = $request->getParameter("id");
        if ($id != null)
            $this->question_channel = Doctrine_Core::getTable('QuestionChannel')->find($id);
    }
}
